﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Catering.View_Operaction;
using System.Data;
using System.IO;
using System.Collections;
using System.Web.Services;

namespace Catering.Catering_Page.Kufang
{
    public partial class Ckgl_Add : UserIsNull
    {
        #region 全局参数

        Catering.View_Operaction_Common voc = new View_Operaction_Common();
        public string m_GroupID = "";     //作业区
        public string m_ClassID = "";     //班组
        public string m_ReturnURL = "";   //ReturnURL返回地址
        public string m_SearchType = "0"; //搜索类型（0：模板日期，1：品号，2：名称）
        public string m_SearchValue = ""; //搜索关键字
        public string m_Type1 = "-10";    //原料大类
        public string m_Type2 = "-10";    //原料细类
        public string m_AddDate = DateTime.Now.ToString("yyyy-MM-dd"); //添加日期
        public int m_Size = 60;//每页记录数量

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            #region 参数获取

            if (!string.IsNullOrEmpty(Request.QueryString["ClassID"])) m_ClassID = Request.QueryString["ClassID"].ToString();
            if (!string.IsNullOrEmpty(Request.QueryString["GroupID"])) m_GroupID = Request.QueryString["GroupID"].ToString();
            if (!string.IsNullOrEmpty(Request.QueryString["SearchType"])) m_SearchType = Request.QueryString["SearchType"].ToString();
            if (!string.IsNullOrEmpty(Request.QueryString["SearchValue"])) m_SearchValue = Request.QueryString["SearchValue"].ToString();
            if (!string.IsNullOrEmpty(Request.QueryString["Type1"])) m_Type1 = Request.QueryString["Type1"].ToString();
            if (!string.IsNullOrEmpty(Request.QueryString["Type2"])) m_Type2 = Request.QueryString["Type2"].ToString();
            if (!string.IsNullOrEmpty(Request.QueryString["AddDate"])) m_AddDate = Request.QueryString["AddDate"].ToString();
            if (!string.IsNullOrEmpty(Request.QueryString["ReturnURL"])) m_ReturnURL = HttpUtility.UrlDecode(Request.QueryString["ReturnURL"].ToString());

            #endregion

            #region 验证

            if (string.IsNullOrEmpty(m_ClassID) || string.IsNullOrEmpty(m_GroupID))
            {
                Response.Write("<script language='javascript'>window.top.location.href='../../loginOut.aspx';</script>");
                Response.End();
            }

            #endregion

            #region 首次加载

            if (!IsPostBack)
            {
                LoadData();
            }

            #endregion
        }

        /// <summary>
        /// 加载页面数据
        /// </summary>
        public void LoadData()
        {
            //设置作业区及班组
            if (!string.IsNullOrEmpty(m_ClassID) && !string.IsNullOrEmpty(m_GroupID))
            {
                voc.DropDownListDataBind_Group(DDL_zuoyequ, this.Base_Companyid);
                DDL_zuoyequ.SelectedValue = m_GroupID;
                voc.DropDownListDataBind_Class(DDL_banzu, DDL_zuoyequ.SelectedItem.Value);
                DDL_banzu.SelectedValue = m_ClassID;
            }

            //设这原料类别
            voc.DropDownListDataBind_RawMaterials(this.DDL_Type1, true);
            this.DDL_Type1.SelectedValue = m_Type1;
            if (this.DDL_Type1.Items.Count > 0)
            {
                voc.DropDownListDataBind_RawMaterialsInfo(this.DDL_Type2, m_Type1, true);
                this.DDL_Type2.SelectedValue = m_Type2;
            }

            //设置搜索
            this.DDL_SearchType.SelectedValue = m_SearchType;
            if (!string.IsNullOrEmpty(m_SearchValue)) this.Txt_MBDate.Text = m_SearchValue;

            //设置添加日期
            if (!string.IsNullOrEmpty(m_AddDate)) this.Txt_AddDate.Text = m_AddDate;

            //设置返回URL
            LB_Return.PostBackUrl = m_ReturnURL;

            //绑定日期文本框事件
            if (this.DDL_SearchType.SelectedIndex == 0)
            {
                this.Txt_MBDate.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'%y-%M-%d'})");
            }
            this.Txt_AddDate.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'%y-%M-%d'})");

            //开始搜索
            BoundData(0);
        }

        /// <summary>
        /// 页面数据绑定
        /// </summary>
        /// <param name="BoundType">绑定类型（0：初始化，1：其他事件）</param>
        private void BoundData(int BoundType)
        {
            DataTable dt = null;
            int SumNum = 0;
            int CurrentIndex = Convert.ToInt32(this.HF_CurrentIndex.Value);
            if (BoundType == 0)
            {
                dt = this.GetFromRecords(m_SearchType, m_SearchValue, m_Type1, m_Type2, m_AddDate, m_Size, 1, out SumNum);
            }
            else
            {
                dt = this.GetFromRecords(this.DDL_SearchType.SelectedValue, this.Txt_MBDate.Text, this.DDL_Type1.SelectedValue, this.DDL_Type2.SelectedValue, this.Txt_AddDate.Text, m_Size, CurrentIndex, out SumNum);
            }
            this.Repeater1.DataSource = dt;
            this.Repeater1.DataBind();
            int MaxPageCount = SumNum / m_Size;
            MaxPageCount = SumNum % m_Size > 0 ? (MaxPageCount + 1) : MaxPageCount;
            CurrentIndex = CurrentIndex > MaxPageCount ? MaxPageCount : CurrentIndex;
            this.Label1.Text = CurrentIndex + "/" + MaxPageCount;
            this.HF_CurrentIndex.Value = CurrentIndex.ToString();
        }

        /// <summary>
        /// 获取搜索结果
        /// </summary>
        /// <param name="StrGroupID"></param>
        /// <param name="StrClassID"></param>
        /// <param name="SearchType"></param>
        /// <param name="StrText"></param>
        /// <param name="StrType1"></param>
        /// <param name="StrType2"></param>
        /// <param name="StrAddDate"></param>
        /// <returns></returns>
        private DataTable GetFromRecords(string SearchType, string StrText, string StrType1, string StrType2, string StrAddDate)
        {
            string str = " AND GroupID= " + m_GroupID + " AND ClassID= " + m_ClassID;
            string notIn = " AND InDBid NOT IN ( SELECT InDBid FROM FromRecords WHERE OutDate='" + StrAddDate + "' AND ClassID= " + m_ClassID + ") ";
            string orderBy = " RTID,RInfoID,RAWName ";
            if (!string.IsNullOrEmpty(StrType1) && StrType1 != "-10") str += " AND RTID=" + StrType1;
            if (!string.IsNullOrEmpty(StrType2) && StrType2 != "-10") str += " AND RInfoID=" + StrType2;
            if (!string.IsNullOrEmpty(StrText))
            {
                if (SearchType == "0")
                {
                    str = str + " AND OutDate='" + Convert.ToDateTime(StrText).ToShortDateString() + "' ";
                }
                else if (SearchType == "1")
                {
                    str = str + " AND InDBID='" + StrText + "' ";
                }
                else if (SearchType == "2")
                {
                    str = str + " AND RAWName LIKE '%" + StrText + "%'";
                }
            }
            DataTable dt = new Catering_Rules.FromRecords().GetQuickFromRecordsData(str, notIn, orderBy);
            return dt;
        }

        /// <summary>
        /// 获取搜索结果
        /// </summary>
        /// <param name="StrGroupID"></param>
        /// <param name="StrClassID"></param>
        /// <param name="SearchType"></param>
        /// <param name="StrText"></param>
        /// <param name="StrType1"></param>
        /// <param name="StrType2"></param>
        /// <param name="StrAddDate"></param>
        /// <returns></returns>
        private DataTable GetFromRecords(string SearchType, string StrText, string StrType1, string StrType2, string StrAddDate, int Size, int CurrentIndex, out int SumNum)
        {
            SumNum = 0;
            string str = " AND GroupID= " + m_GroupID + " AND ClassID= " + m_ClassID;
            string notIn = " AND InDBid NOT IN ( SELECT InDBid FROM FromRecords WHERE OutDate='" + StrAddDate + "' AND ClassID= " + m_ClassID + ") ";
            string orderBy = " RTID,RInfoID,RAWName ";
            if (!string.IsNullOrEmpty(StrType1) && StrType1 != "-10") str += " AND RTID=" + StrType1;
            if (!string.IsNullOrEmpty(StrType2) && StrType2 != "-10") str += " AND RInfoID=" + StrType2;
            if (!string.IsNullOrEmpty(StrText))
            {
                if (SearchType == "0")
                {
                    str = str + " AND OutDate='" + Convert.ToDateTime(StrText).ToShortDateString() + "' ";
                }
                else if (SearchType == "1")
                {
                    str = str + " AND InDBID='" + StrText + "' ";
                }
                else if (SearchType == "2")
                {
                    str = str + " AND RAWName LIKE '%" + StrText + "%'";
                }
            }
            DataTable dt = new Catering_Rules.FromRecords().GetQuickFromRecordsData(str, notIn, orderBy, Size, CurrentIndex, out SumNum);
            return dt;
        }

        public int i = 0;
        public string GetXuNiIndex()
        {
            i += 1;
            return i.ToString();
        }

        /// <summary>
        /// 根据条件获取最新数据的时间(不包含今天)
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public string GetLastDate(string strGroupID, string strClassID)
        {
            string str = " AND GroupID= " + strGroupID + " AND ClassID= " + strClassID + " AND OutDate < '" + DateTime.Now.ToShortDateString() + "'";
            str = new Catering_Rules.FromRecords().GetLastDate(str);
            if (!string.IsNullOrEmpty(str)) return Convert.ToDateTime(str).ToString("yyyy-MM-dd");
            else return "";
        }

        public string GetURL()
        {
            if (!string.IsNullOrEmpty(m_ReturnURL))
            {
                return "Ckgl_Add.aspx?GroupID=" + m_GroupID + "&ClassID=" + m_ClassID + "&SearchType=" + this.DDL_SearchType.SelectedValue + "&SearchValue=" + this.Txt_MBDate.Text.Trim() + "&Type1=" + this.DDL_Type1.SelectedValue + "&Type2=" + this.DDL_Type2.SelectedValue + "&AddDate=" + this.Txt_AddDate.Text.ToString() + "&ReturnURL=" + HttpUtility.UrlEncode(m_ReturnURL);
            }
            return "";
        }

        public string GetKCNumber(string InDBid)
        {
            DateTime datetime = DateTime.Now;
            DateTime.TryParse(this.Txt_AddDate.Text, out datetime);
            datetime = new DateTime(datetime.Year, datetime.Month, datetime.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            decimal sechbalance = new Catering_Rules.BalanceInfo().GetBalance(Convert.ToInt32(m_ClassID), InDBid, datetime);
            return sechbalance.ToString();
        }

        public string GetKCWaring(string strRawBid)
        {
            string strwhere = "ClassID=" + m_ClassID + " and RAWID=" + strRawBid;
            DataTable dt_RoomWaing = new Catering_Rules.RoomWaing().GetList(strwhere).Tables[0];
            if (dt_RoomWaing != null && dt_RoomWaing.Rows.Count > 0) return dt_RoomWaing.Rows[0]["MinContent"].ToString();
            else return "无";
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Save")
            {
                Catering_Model.FromRecords md = new Catering_Rules.FromRecords().GetModel(Convert.ToInt32(e.CommandArgument.ToString()));
                decimal tempnumbers = (this.HF_Number.Value == "" || this.HF_Number.Value == "0") ? 0 : Convert.ToDecimal(this.HF_Number.Value);
                if (md != null)
                {
                    md.id = new Catering_Rules.FromRecords().GetMaxId();
                    if (tempnumbers > 0)
                    {
                        DateTime adddate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                        if (!string.IsNullOrEmpty(this.Txt_AddDate.Text)) DateTime.TryParse(this.Txt_AddDate.Text, out adddate);
                        md.Numbers = tempnumbers.ToString();
                        md.AmountMoney = Toolss.GetMathResult(Convert.ToDecimal(md.Price) * tempnumbers, 2, 3);
                        md.OutDate = adddate;
                        DataTable dt_Raw_A = new Catering_Rules.RawMaterial_Area().GetList("InDBid='" + md.InDBid + "'").Tables[0];
                        Catering_Model.E_RawMaterial md_Raw = new Catering_Rules.T_RawMaterial().GetModel(Convert.ToInt32(dt_Raw_A.Rows[0]["RawID"].ToString()));
                        int result = new Catering_Rules.BalanceInfo().AddFromRecords(md_Raw.id, Convert.ToInt32(md.ClassID), md.InDBid, md.OutDate, md.Numbers, "", md.id);
                        if (result == 3)
                        {
                            md.temp1 = "0";
                            md.temp2 = "";
                            decimal sum = Convert.ToDecimal(md.Numbers);//总重量
                            bool iskg = true;
                            decimal guige = 1;
                            decimal UtilKg = Toolss.GetSpecifications(Convert.ToInt32(md.RAWID), md.CMP, out iskg);
                            guige = iskg ? 1000 : 1;
                            decimal weight = Toolss.GetMathResult(UtilKg * sum, 2, 3);
                            md.SumNumber = weight * guige;
                            md.CMP = new Catering_Rules.Units().GetModel(Convert.ToInt32(md_Raw.temp2)).UName;
                            new Catering_Rules.FromRecords().Add(md);
                            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('添加成功！');location.href='" + GetURL() + "';", true);
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('超过库存，添加失败！');location.href='" + GetURL() + "';", true);
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('数量必须是大于0的数字，添加失败！');location.href='" + GetURL() + "';", true);
                    }
                }
                else
                {
                    //Response.Write("<script>alert('参数错误，添加失败');location.href='" + GetURL() + "'</script>");
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('参数错误，添加失败！');location.href='" + GetURL() + "';", true);
                }
            }
        }

        protected void Btn_Search_Click(object sender, EventArgs e)
        {
            this.HF_CurrentIndex.Value = "1";
            BoundData(1);
        }

        protected void DDL_SearchType_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Txt_MBDate.Text = "";
            if (this.DDL_SearchType.SelectedValue == "0")
            {
                this.Txt_MBDate.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'%y-%M-%d'})");
            }
            else
            {
                this.Txt_MBDate.Attributes.Remove("onfocus");
            }
        }

        protected void DDL_Type1_SelectedIndexChanged(object sender, EventArgs e)
        {
            voc.DropDownListDataBind_RawMaterialsInfo(this.DDL_Type2, this.DDL_Type1.SelectedValue, true);
        }

        /// <summary>
        /// 导出Excel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Btn_Excel_Click(object sender, EventArgs e)
        {
            string strdate = this.Txt_MBDate.Text;
            string searchthype = this.DDL_SearchType.SelectedValue;
            int SumNum = 0;
            if (!string.IsNullOrEmpty(m_ClassID) && !string.IsNullOrEmpty(m_GroupID))
            {
                int CurrentIndex =Convert.ToInt32(this.HF_CurrentIndex.Value);
                DataTable dt = this.GetFromRecords(this.DDL_SearchType.SelectedValue, this.Txt_MBDate.Text, this.DDL_Type1.SelectedValue, this.DDL_Type2.SelectedValue, this.Txt_AddDate.Text);
                if (dt != null && dt.Rows.Count > 0)
                {
                    Microsoft.Office.Interop.Excel.Application excel1 = null;
                    Microsoft.Office.Interop.Excel._Worksheet ws = null;
                    Microsoft.Office.Interop.Excel.Range canbie = null;
                    string stick = DateTime.Now.Ticks.ToString();

                    try
                    {
                        excel1 = new Microsoft.Office.Interop.Excel.Application();
                        excel1.Application.Workbooks.Add(true);//引用Excel工作簿
                        //Microsoft.Office.Interop.Excel._Worksheet ws = new Microsoft.Office.Interop.Excel.WorksheetClass();
                        ws = new Microsoft.Office.Interop.Excel.WorksheetClass();
                        ws = (Microsoft.Office.Interop.Excel._Worksheet)excel1.ActiveSheet;//获取当前活动工作薄
                        //Microsoft.Office.Interop.Excel.Range canbie;//创建Range操作一行作为标题
                        excel1.Visible = false;

                        #region 第一行标题

                        ws.Cells[1, 1] = "序号";
                        ws.Cells[1, 2] = "原料大类";
                        ws.Cells[1, 3] = "原料细类";
                        ws.Cells[1, 4] = "品号";
                        ws.Cells[1, 5] = "品名";
                        ws.Cells[1, 6] = "单价";
                        ws.Cells[1, 7] = "数量";
                        ws.Cells[1, 8] = "库存";
                        ws.Cells[1, 9] = "警戒线";
                        ws.Cells[1, 10] = "单位";
                        canbie = ws.get_Range(ws.Cells[1, 1], ws.Cells[1, 10]);
                        canbie.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;//居中

                        #endregion

                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            string RTName = dt.Rows[i]["RTName"].ToString();
                            string RInfoName = dt.Rows[i]["RInfoName"].ToString();
                            string InDBid = dt.Rows[i]["InDBid"].ToString();
                            string RAWName = dt.Rows[i]["RAWName"].ToString();
                            string Price = dt.Rows[i]["Price"].ToString();
                            string RAWID = dt.Rows[i]["RAWID"].ToString();
                            string CMP = dt.Rows[i]["CMP"].ToString();

                            ws.Cells[2 + i, 1] = (i + 1);
                            ws.Cells[2 + i, 2] = RTName;
                            ws.Cells[2 + i, 3] = RInfoName;
                            ws.Cells[2 + i, 4] = InDBid;
                            ws.Cells[2 + i, 5] = RAWName;
                            ws.Cells[2 + i, 6] = Price;
                            ws.Cells[2 + i, 7] = "";
                            ws.Cells[2 + i, 8] = GetKCNumber(InDBid);
                            ws.Cells[2 + i, 9] = GetKCWaring(RAWID);
                            ws.Cells[2 + i, 10] = CMP;
                        }
                        ws.Cells.EntireColumn.AutoFit();
                        canbie = ws.get_Range(ws.Cells[1, 1], ws.Cells[dt.Rows.Count + 1, 10]);
                        canbie.Borders.LineStyle = 1;
                        dt.Dispose();

                        if (!Directory.Exists(Server.MapPath("../../xls_template"))) Directory.CreateDirectory(Server.MapPath("../../xls_template"));
                        ws.SaveAs(Server.MapPath("../../xls_template") + "\\" + stick + ".xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlAddIn8);
                    }
                    finally
                    {
                        if (excel1 != null)
                        {
                            if (ws != null)
                            {
                                if (canbie != null)
                                {
                                    System.Runtime.InteropServices.Marshal.ReleaseComObject(canbie);
                                    canbie = null;

                                }
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(ws);
                                ws = null;
                            }
                            excel1.Application.Workbooks.Close();
                            excel1.Quit();
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(excel1);
                            Toolss.KillExcel(excel1);
                            excel1 = null;
                            GC.Collect();
                        }
                    }

                    #region 发送

                    try
                    {
                        string path = Server.MapPath("../../xls_template") + "\\" + stick + ".xls";
                        System.IO.FileInfo file = new System.IO.FileInfo(path);
                        Response.Clear();
                        Response.Charset = "GB2312";
                        Response.ContentEncoding = System.Text.Encoding.UTF8;
                        // 添加头信息，,弹出另存为窗口  
                        Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
                        //让浏览器头显示下载信息  
                        Response.AddHeader("Content-Length", file.Length.ToString());
                        // 指定返回一个不能被客户端读取的流，下载  
                        Response.ContentType = "application/ms-excel";
                        //把文件流下载到客户端  
                        Response.WriteFile(file.FullName);
                        Response.Flush();
                        // 停止页面的执行
                        Response.End();
                        //HttpContext.Current.ApplicationInstance.CompleteRequest();

                    #endregion

                    }
                    catch
                    {
                    }
                }
                else
                {
                    View_Operaction_Common.Show(this, "没有可导出的数据");
                }
            }
        }

        [WebMethod]
        public static ArrayList AddChuKu(string StrID, string Number, string StrAddDate)
        {
            ArrayList al = new ArrayList();
            int fid = 0;
            decimal tempnumbers = 0;

            Int32.TryParse(StrID, out fid);
            Decimal.TryParse(Number, out tempnumbers);
            if (fid <= 0 || tempnumbers <= 0)
            {
                al.Add("参数错误，添加失败！");
                return al;
            }

            Catering_Model.FromRecords md = new Catering_Rules.FromRecords().GetModel(fid);
            if (md != null)
            {
                md.id = new Catering_Rules.FromRecords().GetMaxId();
                if (tempnumbers > 0)
                {
                    DateTime adddate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                    if (!string.IsNullOrEmpty(StrAddDate)) DateTime.TryParse(StrAddDate, out adddate);
                    md.Numbers = tempnumbers.ToString();
                    md.AmountMoney = Toolss.GetMathResult(Convert.ToDecimal(md.Price) * tempnumbers, 2, 3);
                    md.OutDate = adddate;
                    DataTable dt_Raw_A = new Catering_Rules.RawMaterial_Area().GetList("InDBid='" + md.InDBid + "'").Tables[0];
                    Catering_Model.E_RawMaterial md_Raw = new Catering_Rules.T_RawMaterial().GetModel(Convert.ToInt32(dt_Raw_A.Rows[0]["RawID"].ToString()));
                    int result = new Catering_Rules.BalanceInfo().AddFromRecords(md_Raw.id, Convert.ToInt32(md.ClassID), md.InDBid, md.OutDate, md.Numbers, "", md.id);
                    if (result == 3)
                    {
                        md.temp1 = "0";
                        md.temp2 = "";
                        decimal sum = Convert.ToDecimal(md.Numbers);//总重量
                        bool iskg = true;
                        decimal guige = 1;
                        decimal UtilKg = Toolss.GetSpecifications(Convert.ToInt32(md.RAWID), md.CMP, out iskg);
                        guige = iskg ? 1000 : 1;
                        decimal weight = Toolss.GetMathResult(UtilKg * sum, 2, 3);
                        md.SumNumber = weight * guige;
                        md.CMP = new Catering_Rules.Units().GetModel(Convert.ToInt32(md_Raw.temp2)).UName;
                        new Catering_Rules.FromRecords().Add(md);
                        al.Add("OK");
                    }
                    else
                    {
                        al.Add("超过库存，添加失败！");
                    }
                }
                else
                {
                    al.Add("数量必须是大于0的数字，添加失败！");
                }
            }
            else
            {
                al.Add("参数错误，添加失败！");
            }
            return al;
        }

        protected void Btn_Pre_Click(object sender, EventArgs e)
        {
            int CurrentIndex = Convert.ToInt32(this.HF_CurrentIndex.Value);
            CurrentIndex = CurrentIndex <= 1 ? 1 : (CurrentIndex - 1);
            this.HF_CurrentIndex.Value = (CurrentIndex + 1).ToString();
            BoundData(1);
        }

        protected void Btn_Nex_Click(object sender, EventArgs e)
        {
            int CurrentIndex = Convert.ToInt32(this.HF_CurrentIndex.Value);
            this.HF_CurrentIndex.Value = (CurrentIndex + 1).ToString();
            BoundData(1);
        }
    }
}